#!/bin/bash

if [ $# == '1' ]; then
  SPIDER_NAME=$1  
else
  echo "usage:"$0" spider-name"
  exit 1
fi

while true; do
{
  node index.js -n $SPIDER_NAME
  if [ -f "$SPIDER_NAME" ]; then
    echo "Stop unexpected, restarting\n"
  else
    echo "task was finished\n"
    exit 0
  fi
} 2>>error.log

done
